package org.etom.impl.ui.util;

import java.io.IOException;
import java.io.PushbackInputStream;
import java.util.zip.GZIPInputStream;

/**
 * The zip utility class.
 */
public class ZipUtility {
  
  private static final int ZIP_MAGIC = 0x504B;
  
  /**
   * Two bytes are read from the method.
   * 
   * @param zipInStream
   * @return <code>true</code> if the stream points to the archived stream
   * @throws IOException
   */
  public static boolean isZipInputStream(PushbackInputStream zipInStream) throws IOException {
    int firstByte = zipInStream.read();
    int secondByte = zipInStream.read();
    zipInStream.unread(secondByte);
    zipInStream.unread(firstByte);
    int magicNumber = ((firstByte << 8) | secondByte);
    return ((magicNumber == GZIPInputStream.GZIP_MAGIC) ||
        (magicNumber == ZIP_MAGIC));
  }
  
}
